package com.framework.auth.controller;

import com.framework.authorization.vo.UserDetailsVo;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhoubb
 * @version V1.0
 * @Date 2020/4/12 17:42
 * @since JDK 1.8
 */
@RestController
@RequestMapping("api")
@Api(value = "UserApiController", description = "用户权限")
public class UserApiController {


    @GetMapping("/getCurrentUser")
    public String getCurrentUser() {
        if(StringUtils.equals("anonymousUser", SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString())) {
            return null;
        }
        UserDetailsVo userDetailsVo = (UserDetailsVo) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(userDetailsVo != null) {
            return userDetailsVo.getUsername();
        }
        return null;
    }

}
